package entity;

import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 63495
 * @Description: 课程类//
 * @date 2022/3/25 21:50
 */
@Getter
@Setter
public class Course extends BaseEntity{

    /** 课程号 */
    private Long id;
    /** 课程名 */
    private String courseName;
    /** 学分 */
    private Integer credit;

    /** 成绩 */
    private List<Score> scores;

    public List<Long> getScoresIds(){
        ArrayList<Long> ids = new ArrayList<>();
        this.scores.forEach(score -> ids.add(score.getId()));
        return ids;
    };

    @Override
    public JSONObject toJson() {
        JSONObject json = new JSONObject();
        json.put("id",this.id);
        json.put("courseName",this.courseName);
        json.put("credit",this.credit);
        return json;
    }
}
